import type { App } from "vue"
import {auth as useAuth} from "@/store"
import router from "@/router"
import {authRouteMode,authBtnMode} from "@/common/config"

/**
 * @param authKeys 按钮权限值
 * @returns true or false是否具备某个按钮的权限
 */
export const hasAuth = (authKeys: string[]) => {
  if(authRouteMode=='local') return true
  const auth=useAuth()
  if(authBtnMode=='request')
  return authKeys.some(v=>auth.accessRequestNameList.includes(v))
  else 
  { 
    const route = router.currentRoute.value
    const actionList:any = route.meta.actionList
    if(!actionList) return true 
    return authKeys.some(v=>actionList.includes(v))
  }
}

/**
 * 
 * @param hasFooter 模态框是否包含footer
 * @returns 模态框body可以占据的最大高度
 */
export const getModalBodyMaxHeight=(hasFooter=true)=>{
  //return  document.documentElement.clientHeight-(55+53)
  //55是modal的header占据的高度，53是modal的footer占据的高度,110是给屏幕留白的高度，因为默认top为100。
  if(hasFooter)
  return document.documentElement.clientHeight-(55+53+110) 
  else
  return document.documentElement.clientHeight-(55+110) 
}


export default (app: App) => {
  app.config.globalProperties.$hasAuth = hasAuth
  app.config.globalProperties.$getModalBodyMaxHeight = getModalBodyMaxHeight
  app.config.globalProperties.$window = window

}